package com.cm.stock.manager.utils;

import java.security.Key;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import org.springframework.context.ApplicationContext;
import com.cm.stock.manager.dto.UserDTO;


public class CMStockManagerUtils {

	public static ApplicationContext CONTEXT;
	public static UserDTO CURRENT_USER;
	
	
	public static String encrypt(String password,String key){
		try
		{
			Key clef = new SecretKeySpec(key.getBytes("ISO-8859-2"),"Blowfish");
			Cipher cipher=Cipher.getInstance("Blowfish");
			cipher.init(Cipher.ENCRYPT_MODE,clef);
			return new String(cipher.doFinal(password.getBytes()));
		}
		catch (Exception e)
		{
			return null;
		}
	}
	public static String decrypt(String password,String key){
		try
		{
			Key clef = new SecretKeySpec(key.getBytes("ISO-8859-2"),"Blowfish");
			Cipher cipher=Cipher.getInstance("Blowfish");
			cipher.init(Cipher.DECRYPT_MODE,clef);
			return new String(cipher.doFinal(password.getBytes()));
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.out.println(e);
			return null;
		}
	}
}
